package com.train.tools;

import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@Service
public class DateFormat {

    public static String dateToStr(java.sql.Timestamp time, String strFormat) {
        SimpleDateFormat df = new SimpleDateFormat(strFormat);
        String str = df.format(time);
        return str;
    }

    public static java.sql.Date stringToDate(String strTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d=null;
        try {
            d =formatter.parse(strTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        java.sql.Date date=new java.sql.Date(d.getTime());
        return date;
    }
}
